//---------------------------------------------------------------------------

#ifndef CWinIOH
#define CWinIOH
//---------------------------------------------------------------------------
#endif

#include <windows.h>

#pragma pack(push)
#pragma pack(1)

struct tagPhysStruct
{
	DWORD64 dwPhysMemSizeInBytes;
	DWORD64 pvPhysAddress;
	DWORD64 PhysicalMemoryHandle;
	DWORD64 pvPhysMemLin;
	DWORD64 pvPhysSection;
};

struct tagPortStruct
{
	USHORT wPortAddr;
	ULONG dwPortVal;
	UCHAR bSize;
};

#pragma pack(pop)



class CWinIo
{
public:
    CWinIo();
    ~CWinIo()
    {
       Close();
    }
    bool Init();
    void Close();

    bool IsWin64OS();


    bool WriteLpt(BYTE bData);
    bool IsLoaded() { return m_fModuleLoaded;}
private:

    typedef bool (WINAPI * _InitializeWinIo)(void);
    typedef void (WINAPI * _ShutdownWinIo)(void);
    typedef PBYTE (WINAPI * _MapPhysToLin)(tagPhysStruct &PhysStruct);
    typedef bool (WINAPI * _UnmapPhysicalMemory)(tagPhysStruct &PhysStruct);
    typedef bool (WINAPI * _GetPhysLong)(PBYTE pbPhysAddr, PDWORD pdwPhysVal);
    typedef bool (WINAPI * _SetPhysLong)(PBYTE pbPhysAddr, DWORD dwPhysVal);
    typedef bool (WINAPI * _GetPortVal)(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);
    typedef bool (WINAPI * _SetPortVal)(WORD wPortAddr, DWORD dwPortVal, BYTE bSize);
    typedef bool (WINAPI * _InstallWinIoDriver)(PWSTR pszWinIoDriverPath, bool IsDemandLoaded = false);
    typedef bool (WINAPI * _RemoveWinIoDriver)(void);


	struct {
		_InitializeWinIo       InitializeWinIo;
		_ShutdownWinIo         ShutdownWinIo;
		_MapPhysToLin          MapPhysToLin;
		_UnmapPhysicalMemory   UnmapPhysicalMemory;
		_GetPhysLong           GetPhysLong;
		_SetPhysLong           SetPhysLong;
		_GetPortVal            GetPortVal;
		_SetPortVal            SetPortVal;
		_InstallWinIoDriver    InstallWinIoDriver;
		_RemoveWinIoDriver     RemoveWinIoDriver;
	} dWinIoDrv;


   bool m_fInit;
   bool m_fModuleLoaded;

   CLibrary	DLL;
};
